package com.ultimatech.wxservice.web;

import com.ultimatech.wxservice.combusiness.service.IWxApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by zhangleping on 2017/6/16.
 *
 * 定时任务
 */

@Component
@Configurable
@EnableScheduling
public class ScheduledTasks {

    private Logger logger= LoggerFactory.getLogger(ScheduledTasks.class);

    @Autowired
    private IWxApi wxApi;

    public IWxApi getWxApi() {
        return wxApi;
    }

    public void setWxApi(IWxApi wxApi) {
        this.wxApi = wxApi;
    }

    @Scheduled(fixedDelay = 6600*1000)
    public void refreshAllAccessToken(){
        logger.info("更新微信公众号access_token的任务已经启动");
        this.getWxApi().refreshAllAccessTokens();
        logger.info("更新微信公众号access_token的任务已经结束");
    }
}
